﻿@using KPIS.GERP.Models.ICM
@model IEnumerable<BidderCollateral>

@{
    Layout = "~/Views/Shared/_EmptyLayout.cshtml";
    var modelBidder = (Bidder)ViewBag.ModelBidder;
    //int BidderId = ((Model != null) && Model.Count() > 0 && (Model.FirstOrDefault().BidderId != null)) ? (int)Model.FirstOrDefault().BidderId : 0;
    ViewBag.Title = "หลักประกัน";
    ViewBag.Descr = "ข้อมูล" + ViewBag.Title + " ของผู้ประมูล " + modelBidder.MasContact.NameTh ;
   
}

@using (Html.BeginForm("DeleteAll", "BidderCollateral", FormMethod.Post))
{
     @Html.AntiForgeryToken()

        <div class="row-fluid">
         <div class="block-button-menu-above">
            @Html.ActionLink("เพิ่ม", "Create", new { BidderId = modelBidder.BidderId }
            , new { @class="btn btn-small btn-success button-standard-width", role="button" })
            @Html.ButtonDeleteAll()
        </div>

        @Html.ValidationSummary(true, "ข้อมูลไม่ถูกต้อง!", new { @class = "alert alert-error" })
             @* Header Table *@
             <div class="row-fluid">
                <div class="table-header span12">
				    <div class="span10">
                        @ViewBag.Title
				    </div>
				     @Html.Partial("_ExportButton")
                </div>
            </div>
            <table id="table" class="table table-striped table-bordered table-hover" aria-describedby="table_info">
                <thead>
                    <tr>
                        <th class="center" style="width:50px;">
                            <label>
                                <input type="checkbox" />
                                <span class="lbl"></span>
                            </label>
                        </th>  
                        <th>
                            @Html.DisplayNameFor(model => model.FirstOrDefault().Code)                         
                        </th>
                         <th>
                            @Html.DisplayNameFor(model => model.FirstOrDefault().ColTypeId)           
                        </th>
                         <th>
                            @Html.DisplayNameFor(model => model.FirstOrDefault().Amount)     
                        </th>
                         @*<th>
                            @Html.DisplayNameFor(model => model.FirstOrDefault().Descr) 
                        </th>*@
                         <th>
                           @Html.DisplayNameFor(model => model.FirstOrDefault().ReceiptNo) 
                        </th>
                        <th>
                           @Html.DisplayNameFor(model => model.FirstOrDefault().ReturnDate) 
                        </th>
                         <th>
                           @Html.DisplayNameFor(model => model.FirstOrDefault().ColStatusId) 
                        </th>
                        <th class="center" style="width:80px;">&nbsp;
                        </th>
                    </tr>
                </thead>
                <tbody>
                @foreach (var m in Model ?? new List<BidderCollateral>())
                {
                    <tr>
                        <td class="center">
							<!-- Check box all for delete multiple records -->
                            <label>
                                <input type="checkbox" name="deleteIds" value="@(m.BidderColId)" />
                                <span class="lbl"></span>
                            </label>
                        </td>
						<td>
							@Html.ActionLink(@m.Code, "Details", new { Id = m.BidderColId })
						</td>
						<td>
							@Html.ActionLink(@m.CollateralType.LookUpName, "Details", new { Id = m.BidderColId })
						</td>
						<td>
							@(m.Amount.HasValue ? m.Amount.Value.ToString("#,##0.00") : "0.00") บาท
						</td>
                        @*<td>
							@Html.DisplayFor(model => m.Descr)
						</td>*@
                        <td>
							@Html.DisplayFor(model => m.ReceiptNo)
						</td>
                        <td>
							@Html.DisplayFor(model => m.ReturnDate)
						</td>
                        <td>
							@Html.DisplayFor(model => m.CollateralStatus.LookUpName)
						</td>                       
                        <td class="td-actions">
                            @*@if (ViewBag.bEditable)
                            {*@
							    @Html.Partial("_ButtonMenuEachRow", new KPIS.GERP.Models.ViewModel.ExportGrid
                                {
                                    Id = m.BidderColId,
                                    DetailsUrl = Url.Action("Details") + "/" + m.BidderColId,
                                    EditUrl = Url.Action("Edit") + "/" + m.BidderColId,
                                    DeleteUrl = Url.Action("Delete") + "/" + m.BidderColId
                                })
                            @*}
                            else{
                                @Html.Partial("_ButtonMenuEachRow", new KPIS.GERP.Models.ViewModel.ExportGrid
                                {
                                    Id = m.BidderColId,
                                    DeleteUrl = Url.Action("Delete") + "/" + m.BidderColId
                                })
                            }*@
                               
                        </td>
                    </tr>
                }
                </tbody>

            </table>
       </div>
}

@section scripts {
    
	<script type="text/javascript">
		$(function () {
			var oTable1 = $('#table').dataTable({
				"aoColumns": [
                    { "bSortable": false },
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    //null,
                    { "bSortable": false }
				]
			});

			$('table th input:checkbox').on('click', function () {
				var that = this;
				$(this).closest('table').find('tr > td:first-child input:checkbox')
				.each(function () {
					this.checked = that.checked;
					$(this).closest('tr').toggleClass('selected');
				});

			});

			$('[data-rel=tooltip]').tooltip();

			$("form").submit(function () {
				var currentForm = this;
				bootbox.confirm(function (result) {
					var _result = result;
					if (result) {
						$.ajax({
						    url: '@(Url.Action("DeleteAll", "BidderCollateral"))',
							type: "post",
							dataType: "json",
							data: $(currentForm).serialize(),
							success: function (result) {
								if (result.success) {
									location.reload();
								}
								else {
								}
							}
						});
					}
				})
				return false;

			});

		})

	</script>

}